ARD2  1.00 for Rev B. Hardware
Airbag Reference Demonstrator using MPC5604P
MMA68xx.h File Reference

Driver for central accelerometer. More...

Go to the source code of this file.

Defines

#define TRUE   (1u)
#define CLEAR   (0u)
#define BITS_IN_NIBBLE   (4u)
#define BITS_IN_BYTE   (8u)
#define BYTES_IN_16   (2u)
#define BYTES_IN_32   (4u)
#define BIT_DEFINITION
#define BIT0   (1u << 0u)
#define BIT1   (1u << 1u)
#define BIT2   (1u << 2u)
#define BIT3   (1u << 3u)
#define BIT4   (1u << 4u)
#define BIT5   (1u << 5u)
#define BIT6   (1u << 6u)
#define BIT7   (1u << 7u)
#define BIT8   (1u << 8u)
#define BIT9   (1u << 9u)
#define BIT10   (1u << 10)
#define BIT11   (1u << 11)
#define BIT12   (1u << 12)
#define BIT13   (1u << 13)
#define BIT14   (1u << 14)
#define BIT15   (1u << 15)
#define BIT16   (1u << 16)
#define BIT17   (1u << 17)
#define BIT18   (1u << 18)
#define BIT19   (1u << 19)
#define BIT20   (1u << 20)
#define BIT21   (1u << 21)
#define BIT22   (1u << 22)
#define BIT23   (1u << 23)
#define BIT24   (1u << 24)
#define BIT25   (1u << 25)
#define BIT26   (1u << 26)
#define BIT27   (1u << 27)
#define BIT28   (1u << 28)
#define BIT29   (1u << 29)
#define BIT30   (1u << 30)
#define BIT31   (1u << 31)
#define MMA6800_MEMORY_MAP_SIZE   (0x18u)
#define MMA6800_SN0   (0x00u << 8u)
#define MMA6800_SN1   (0x01u << 8u)
#define MMA6800_SN2   (0x02u << 8u)
#define MMA6800_SN3   (0x03u << 8u)
#define MMA6800_STDEFL_X   (0x04u << 8u)
#define MMA6800_STDEFL_Y   (0x05u << 8u)
#define MMA6800_FCTCFG_X   (0x06u << 8u)
#define MMA6800_FCTCFG_Y   (0x07u << 8u)
#define MMA6800_PN   (0x08u << 8u)
#define MMA6800_RESERVED3   (0x09u << 8u)
#define MMA6800_DEVCTL   (0x0Au << 8u)
#define MMA6800_DEVCFG   (0x0Bu << 8u)
#define MMA6800_DEVCFG_X   (0x0Cu << 8u)
#define MMA6800_DEVCFG_Y   (0x0Du << 8u)
#define MMA6800_ARMCFGX   (0x0Eu << 8u)
#define MMA6800_ARMCFGY   (0x0Fu << 8u)
#define MMA6800_ARMT_XP   (0x10u << 8u)
#define MMA6800_ARMT_YP   (0x11u << 8u)
#define MMA6800_ARMT_XN   (0x12u << 8u)
#define MMA6800_ARMT_YN   (0x13u << 8u)
#define MMA6800_DEVSTAT   (0x14u << 8u)
#define MMA6800_COUNT   (0x15u << 8u)
#define MMA6800_OFF_CORR_X   (0x16u << 8u)
#define MMA6800_OFF_CORR_Y   (0x17u << 8u)
#define MMA6800_PCM_ON   (0x10u)
#define MMA6800_ARM_MOVEAVGHIGH   (0x20u)
#define MMA6800_ARM_MOVEAVGLOW   (0x21u)
#define MMA6800_ARM_COUNTHIGH   (0x30u)
#define MMA6800_ARM_COUNTLOW   (0x31u)
#define MMA6800_ARM_UNFILTHIGH   (0x40u)
#define MMA6800_ARM_UNFILTTLOW   (0x41u)
#define MMA6800_READ_REGISTER   (0x00u)
#define MMA6800_WRITE_REGISTER   (0x40u)
#define MMA6800_READ_X   (BIT0)
#define MMA6800_READ_Y   (BIT1)
#define MMA6800_READ_ACCEL   (0x2000u)
#define MMA6500_READ_ACCEL   (0x2008u)
#define MMA6800_X_AXIS   (0x0000u)
#define MMA6800_Y_AXIS   (0x4000u)
#define MMA6800_ARM_ENABLE   (0x0002u)
#define MMA6800_ARM_DISABLE   (0x0000u)
#define MMA6800_SIGNED_DATA   (0x0000u)
#define MMA6800_UNSIGNED_DATA   (0x0004u)
#define MMA6800_OFFSET_CANCELLED   (0x0000u)
#define MMA6800_RAW_DATA   (0x1000u)
#define MMA6800_TRANSFER_MODE_IS_SCHEDULED   (0u)
#define MMA6800_TRANSFER_MODE_IS_IMMEDIATE   (1u)
#define MMA6800_REGISTER_RESP_SIGNATURE   (BIT11 | BIT10)
#define MMA6800_ACCEL_READING   (0x01u)
#define MMA6800_REGISTER_RESPONSE   (0x02u)
#define MMA6800_TIMED_OUT   (0x04u)
#define MMA6800_INVALID_PARITY   (0x08u)
#define MMA6800_INVALID_MEMORY_LOCATION   (0x10u)
#define MMA6800_ERROR_DATAGRAM   (0x20u)
#define MMA6800_ERROR_ACCEL   (0x40u)
#define MESQUITE   1
#define SYCAMORE   2
#define MMA6800_RAW_ACCEL_MASK   (0x03FFu)
#define MMA6500_RAW_ACCEL_MASK   (0xC3FFu)
#define MMA6800_GLOBAL_BUFFER_SIZE   (30u)
#define MMA6800_ERROR_MASK   ((uint16_t)0x6000u)
#define MMA6800_MSG_BUFFER_SIZE   50
#define RAW_MMA_ACCEL_ARRAY_SIZE   3u
#define N_ELEMENTS(X)   (sizeof(X)/sizeof(*(X)))

Functions

uint8_t u8fnMMA6800ReadRegister (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8TransferMode, uint16_t u16Register, uint16_t *pu16DataRead)
 Reads one register from the MMA6800.
uint8_t u8fnMMA6800WriteRegister (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8TransferMode, uint16_t u16Register, uint8_t u8ValueToWrite, uint16_t *pu16DataRead)
 Writes to one register of the MMA6800.
uint8_t u8fnMMA6800Reset (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8TransferMode)
 Performs a soft-reset of the device.
uint8_t u8fnMMA6800ReadAccel (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8TransferMode, const uint8_t cu8Axis, const uint8_t cu8ConfigMemory, uint16_t *pu16AccelResults, const uint8_t cu8Accel)
 Reads acceleration from the X, Y or both axes.
uint8_t u8fnMMA6800ExtractRegisterResponse (const uint16_t *pu16RawResponse, uint8_t *pu8Response, uint8_t u8Size)
 Extracts 8-bit information from raw data.
uint8_t u8fnMMA6800ExtractAccelResponse (const uint16_t *pu16RawResponse, uint16_t *pu16Response, uint8_t u8Size, const uint8_t cu8Accel)
 Extracts 10-bit accel information from raw data.
uint8_t u8fnMMA6800BatchOp (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint16_t *pu16DataToSend, uint16_t *pu16UnfilteredDataReceived, uint8_t u8Size)
 Sends n transfers to the device, and reads-back as well.
uint8_t u8fnMMA6800ScheduledBatchOp (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint16_t *pu16DataToSend, uint16_t *pu16UnfilteredDataReceived, uint8_t u8Size)
 Schedules n transfers to the device.

Variables

const uint16_t cau16MMA6800ReadAllRegisters []
const uint16_t cau16MMA6800Reset []
const uint16_t cau16MMA6800PerformAccelReading []
const uint16_t cau16MMA6500PerformAccelReading []
uint8_t(*const u8pfnMMA6800BatchOp [])(const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint16_t *pu16DataToSend, uint16_t *pu16UnfilteredDataReceived, uint8_t u8Size)
uint8_t gau8MMA6800GlobalResult [MMA6800_GLOBAL_BUFFER_SIZE]

Detailed Description

Driver for central accelerometer.

Copyright (c) 2011 Freescale Semiconductor Freescale Confidential Proprietary

Author:
Freescale Semiconductor
SASD Automotive
R11515
R54967
Version:
Date:
Warning:
(If needed)

History:


Function Documentation

uint8_t u8fnMMA6800BatchOp ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint16_t *  pu16DataToSend,
uint16_t *  pu16UnfilteredDataReceived,
uint8_t  u8Size 
)

Sends n transfers to the device, and reads-back as well.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
pu16DataToSend,:Pointer to complete message to send. Parity is calculated within the function. Constant tables in this file should be used accordingly.
pu16UnfilteredDataReceived,:Pointer to where part's response should be stored. This is the complete response, no filters.
u8Size,:Number of words to send/receive.
Returns:
Status. Clear when no error found, otherwise MMA6800_TIMED_OUT if timed out, or DSPI_BUSY_WITH_PREVIOUS_TX if it can't be written to.
uint8_t u8fnMMA6800ExtractAccelResponse ( const uint16_t *  pu16RawResponse,
uint16_t *  pu16Response,
uint8_t  u8Size,
const uint8_t  cu8Accel 
)

Extracts 10-bit accel information from raw data.

Parameters:
pu16RawResponse,:pointer to 16-bit, unfiltered response.
pu16Response,:pointer to where filtered data should be stored.
u8Size,:Size of raw responses to filter.
cu8Accel,:Choice between MESQUITE and SYCAMORE sensor.
Returns:
Status. Clear when no error found, MMA6800_INVALID_PARITY if at least one of the elements had incorrect parity; MMA6800_ERROR_ACCEL if another error has been found.
uint8_t u8fnMMA6800ExtractRegisterResponse ( const uint16_t *  pu16RawResponse,
uint8_t *  pu8Response,
uint8_t  u8Size 
)

Extracts 8-bit information from raw data.

Parameters:
pu16RawResponse,:pointer to 16-bit, unfiltered response.
pu8Response,:pointer to where filtered data should be stored.
u8Size,:Size of raw responses to filter.
Returns:
Status. Clear when no error found, otherwise MMA6800_INVALID_PARITY.
uint8_t u8fnMMA6800ReadAccel ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8TransferMode,
const uint8_t  cu8Axis,
const uint8_t  cu8ConfigMemory,
uint16_t *  pu16AccelResults,
const uint8_t  cu8Accel 
)

Reads acceleration from the X, Y or both axes.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
cu8Axis,:1 for X, 2 for Y, or 3 for both. Any other value will result in an X-axis reading.
cu8ConfigMemory,:Index to perform accel reading with a given configuration. According to the spec: [0] = Offset Compensated, Signed data, ARM disabled [1] = Offset Compensated, Signed data, ARM enabled [2] = Offset Compensated, Unsigned data, ARM disabled [3] = Offset Compensated, Unsigned data, ARM enabled [4] = Raw data, Signed data, ARM disabled [5] = Raw data, Signed data, ARM enabled [6] = Raw data, Unsigned data, ARM disabled [7] = Raw data, Unsigned data, ARM enabled Any other value will return an error code.
pu16AccelResults,:Pointer to location where accel reading(s) will be stored.
cu8Accel,:Choice between MESQUITE and SYCAMORE sensor.
Returns:
Status. Clear when no error found, otherwise MMA6800_INVALID_MEMORY_LOCATION if a cu8ConfigMemory value is out of the expected range; MMA6800_ERROR_ACCEL if the accelerometer value passed in cu8Accel is invalid; MMA6800_INVALID_PARITY if at least one of the elements had incorrect parity; MMA6800_TIMED_OUT if timed out, or DSPI_BUSY_WITH_PREVIOUS_TX if it can't be written to; MAILBOX_IS_BEING_WRITTEN if in scheduled mode and there is a mailbox problem.
uint8_t u8fnMMA6800ReadRegister ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8TransferMode,
uint16_t  u16Register,
uint16_t *  pu16DataRead 
)

Reads one register from the MMA6800.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
u16Register,:Address of the register to read with LSB in BIT8. For simplicity, use the #defines in this same file.
cu8TransferMode,:either MMA6800_TRANSFER_MODE_IS_SCHEDULED or MMA6800_TRANSFER_MODE_IS_IMMEDIATE - first option will schedule the transfer using the scheduler, second one will execute the command immediately
pu16DataRead,:Pointer to where data read should be stored. two 16-bit words will be stored: First to be disregarded, second word will contain two 8-bit words: First is status (should read $2E or $3E), second one is data). The second 16-bit word can be fed as argument to u8fnMMA6800ExtractRegisterResponse to get a valid answer.
Returns:
Status. Clear when no error found, or DSPI_BUSY_WITH_PREVIOUS_TX if it can't be written to; MAILBOX_IS_BEING_WRITTEN if in scheduled mode and there is a mailbox problem.
uint8_t u8fnMMA6800Reset ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8TransferMode 
)

Performs a soft-reset of the device.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
cu8TransferMode,:either MMA6800_TRANSFER_MODE_IS_SCHEDULED or MMA6800_TRANSFER_MODE_IS_IMMEDIATE - first option will schedule the transfer using the scheduler, second one will execute the command immediately
Returns:
This status byte is actually the read value from the DEVCFG register within the device.
uint8_t u8fnMMA6800ScheduledBatchOp ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint16_t *  pu16DataToSend,
uint16_t *  pu16UnfilteredDataReceived,
uint8_t  u8Size 
)

Schedules n transfers to the device.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
pu16DataToSend,:Pointer to complete message to send. Parity is calculated within the function. Constant tables in this file should be used accordingly.
pu16UnfilteredDataReceived,:Pointer to where part's response should be stored. This is the complete response, no filters.
u8Size,:Number of words to send/receive.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN.
uint8_t u8fnMMA6800WriteRegister ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8TransferMode,
uint16_t  u16Register,
uint8_t  u8ValueToWrite,
uint16_t *  pu16DataRead 
)

Writes to one register of the MMA6800.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
u16Register,:Address of the register to write with LSB in BIT8. For simplicity, use the #defines in this same file.
u8ValueToWrite,:8-bit value to be written to the register.
cu8TransferMode,:either MMA6800_TRANSFER_MODE_IS_SCHEDULED or MMA6800_TRANSFER_MODE_IS_IMMEDIATE - first option will schedule the transfer using the scheduler, second one will execute the command immediately
pu16DataRead,:Pointer to where data read should be stored. two 16-bit words will be stored: First to be disregarded, second word will contain two 8-bit words: First is status (should read $2E or $3E), second one is data). The second 16-bit word can be fed as argument to u8fnMMA6800ExtractRegisterResponse to get a valid answer.
Returns:
Status. Clear when no error found, or DSPI_BUSY_WITH_PREVIOUS_TX if it can't be written to; MAILBOX_IS_BEING_WRITTEN if in scheduled mode and there is a mailbox problem.